package orthoplanner.com.google.code.tools;

import java.awt.Color;
import java.awt.Point;

import processing.core.PApplet;

public class Circle implements Drawable{
	private Color color;
	private int strokeWeight;
	private final String name;
	private int startX, startY, endX, endY;
		public Circle(int startX, int startY) {
		this.startX = startX;
		this.startY = startY;
		this.endX = startX + 2;
		this.endY = startY + 2;
		name="Circle";
		color=new Color(93, 197, 255);
		strokeWeight=1;
	}
	public Point getCenter(){
	return new 	Point(Math.round(this.getCx()),Math.round(this.getCy()));	
	}
	public int getStartX() {
		return startX;
	}

	public void setStartX(int startX) {
		this.startX = startX;
	}

	public int getStartY() {
		return startY;
	}

	public void setStartY(int startY) {
		this.startY = startY;
	}

	public int getEndX() {
		return endX;
	}

	public void setEndX(int endX) {
		this.endX = endX;
	}

	public int getEndY() {
		return endY;
	}

	public void setEndY(int endY) {
		this.endY = endY;
	}

	public void setEnd(Point p) {
		this.endX = p.x;
		this.endY = p.y;
	}

	public float getCx() {
		return startX + ((endX - startX) / 2.0F);
	}

	public float getCy() {
		return startY + ((endY - startY) / 2.0F);
	}

	public float getRadius() {
		return PApplet.dist(startX, startY, endX, endY)/2.0F;
	}

	public void configure(Point p) {
		if(this.getRadius()>15){
		long x=Math.round(p.distance(this.getCenter())-this.getRadius());
		startX-=x;
		endX+=x;
		startY-=x;
		endY+=x;
		}
		
	}

	public void draw(PApplet imgViewer) {
		imgViewer.stroke(color.getRed(),color.getGreen(),color.getBlue());
		imgViewer.strokeWeight(strokeWeight);
		imgViewer.noFill();
		imgViewer.ellipse(this.getCx(), this.getCy(), 2*this.getRadius(), 2*this.getRadius());
		imgViewer.fill(color.getRed(),color.getGreen(),color.getBlue());
		imgViewer.ellipse(this.getCx(), this.getCy(), 10, 10);
		imgViewer.line(this.getCx()+this.getRadius(), this.getCy(),this.getCx()-this.getRadius(), this.getCy());
		imgViewer.fill(color.getRed(),color.getGreen(),color.getBlue());
		imgViewer.text(Math.round(this.getRadius()),this.getCx()+10,this.getCy()-10);
	}

	public Boolean isConfigurable(Point p) {
		return Math.abs(p.distance(this.getCenter())-this.getRadius())<15;
	}

	public Boolean isMovable(Point p) {
		return this.getCenter().distance(p)<15;
	}

	public void move(int x, int y) {
		this.endX+=x;
		this.startX+=x;
		this.endY+=y;
		this.startY+=y;
		
	}
	public String getName() {
		return name;
	}
	public void setColor(Color color) {
		this.color=color;
	}
	public void setStroke(int value) {
	this.strokeWeight=value;	
	}
	public Color getColor() {
		return this.color;
	}
	public int getStrokeWeight() {
		return strokeWeight;
	}
	

}
